import UIManage from "../gui/UIManage";

export type pos = Laya.Sprite | Laya.Point | simplePos | simplePosObj;

export type simplePos = [number, number];

export type simplePosObj = { x: number, y: number };

export interface itmeSign {
    sign: string;
}

/**
 * 坐标格式化
 * @param p 转换坐标
 * @param parent 父级，默认特效层
 * @returns 
 */
export function getPos(p: pos, parent?: Laya.Sprite): simplePos {
    if (p instanceof Laya.Sprite) {
        let pos = p.localToGlobal(Laya.Point.TEMP.setTo(p.width >> 1, p.height >> 1));
        parent = parent == null ? UIManage.Instance().effLayer : parent;
        parent.globalToLocal(pos);
        let temp: simplePos = [pos.x, pos.y]
        return temp;
    }

    if (p instanceof Laya.Point) {
        return [p.x, p.y];
    }

    if (p instanceof Array) {
        return p;
    }

    return [p.x, p.y];
}

/**
 * 计算距离
 * @param x 
 * @param y 
 * @returns 
 */
export function distance(x: pos, y: pos) {
    let a = getPos(x), b = getPos(y);
    return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]))
}

//金币坐标
export function goldPo(): simplePos {
    return [100, 100];
}

